/***************************************************************************
 *   Copyright (C) 2008 by BogDan Vatra                                    *
 *   bogdan@licentia.eu                                                    *
 *                                                                         *
 *   This program is free software: you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/
#include <QDoubleSpinBox>

#include "transferdescarcarespinboxdelegate.h"


TransferDescarcareSpinBoxDelegate::TransferDescarcareSpinBoxDelegate(QObject* parent) :QItemDelegate(parent)
{
}

QWidget* TransferDescarcareSpinBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const 
{
	QDoubleSpinBox * spinbox= new QDoubleSpinBox(parent);
	spinbox->setMinimum( 0 );
	spinbox->setMaximum(index.model()->data(index.model()->index(index.row(), 1),Qt::DisplayRole).toDouble());
	return spinbox;
}

void TransferDescarcareSpinBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const 
{
	static_cast<QDoubleSpinBox*>(editor)->setValue(index.model()->data(index, Qt::EditRole).toDouble());
}

void TransferDescarcareSpinBoxDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const 
{
	static_cast<QDoubleSpinBox*>(editor)->interpretText();
	model->setData(index, static_cast<QDoubleSpinBox*>(editor)->value(), Qt::EditRole);
}

void TransferDescarcareSpinBoxDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const 
{
	editor->setGeometry(option.rect);
}
